import axiosInstance from '@/axios/interceptors/axios'
import { API_DEFAULT_CONFIG } from '@/axios/index'
const { mockBaseURL, openMock } = API_DEFAULT_CONFIG
function request(options: ApiOptions.Options) {
  /**
   * 线上 | 线下mock 请求
   * mock {Boolean} 单个请求是否mock线下
   * openMock {Boolean} 所有请求mock线下
   */
  const isMock = options.mock || openMock
  const path = isMock && options.mockPath ? options.mockPath : options.url
  const baseURL = isMock && mockBaseURL
  if (baseURL) {
    options.baseURL = baseURL
    options.url = path
  }

  // post请求: params参数赋值给data
  if (options.method === ApiOptions.Method.POST && options.params) {
    options.data = options.params
    options.params = null
  }

  return axiosInstance(options)
}

export default request
